package com.itita.weibo.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import weibo4andriod.Comment;
import weibo4andriod.DirectMessage;
import weibo4andriod.Status;
import weibo4andriod.User;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.itita.weibo.manager.MainService;
import com.itita.weibo.manager.WeiboManager;
import com.itita.weibo.model.Task;
import com.itita.weibo.ui.ListAllFriendsActivity;
import com.itita.weibo.ui.R;
/**
 * 微博工具
 * 
 * @author 焦明 2010-5-4 13:00
 *
 */
public final class WeiboUtil {
	
	public static final String COMMENT_NUM = "COMMENT_NUM";
	
	public static final String RT_NUM = "RT_NUM";
	
	public static List commentsList4OneStatus;
	
//	public static User currentAutoLoginingUser = null;
	
	
	/**
	 * 启动MainService服务
	 * @param context 上下文
	 */
	public static final void startMainSevice(Context context){
		Intent it = new Intent(context, MainService.class);
		context.startService(it);
	}
	/**
	 * 去掉Activity标题栏
	 * @param activity
	 */
    public static final void closeWindowTitle(Activity activity){
    	activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    
    /**
     * 去掉Activity的标题栏和状态状态栏
     * @param activity
     */
    public static final void closeWindowStatusBar(Activity activity){
        //去掉任务条
    	activity.getWindow().setFlags(
        		WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        		WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    
    /**
     * 判断字符串是否为空
     * @param str 要判断的字符串
     * @return 是否为空
     */
    public static final boolean strIsNotEmpty(String str){
    	if(str != null && str.length() != 0){
    		return true;
    	}
    	return false;
    }
    /**
     *  抓出微博信息中的链接
     * @param str  微博信息
     * @param textView 装在微博信息的视图
     */
    public static final void addURLSpan(String str, TextView textView) {
    	char strarray[];
    	
		SpannableString ss = new SpannableString(str);
		strarray = str.toCharArray();
		int l = str.length() - 10;
		for (int i = 0; i < l; i++) {
			if ((i + 7 < l) 
					&& strarray[i] == 'h' 
					&& strarray[i + 1] == 't'
					&& strarray[i + 2] == 't'
					&& strarray[i + 3] == 'p'
					&& strarray[i + 4] == ':' 
					&& strarray[i + 5] == '/'
					&& strarray[i + 6] == '/') {
				StringBuffer sb = new StringBuffer("http://");
				for (int j = i + 7; true; j++) {
					if (strarray[j] == ' ' || j == str.length() - 1) {
						Log.d("http", sb.toString());
						ss.setSpan(new URLSpan(sb.toString()), i, j,
						Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
						i = j;
						break;
					} else {
						sb.append(strarray[j]);
					}
				}
			}
		}
		l = str.length();
		StringBuffer sb = null;
		boolean start = false;
		int startIndex = 0;
		for (int i = 0; i < l; i++) {
			if (strarray[i] == '@') {
				start = true;
				sb = new StringBuffer("weibo20://view/");
				startIndex = i;
			} else {
				if (start) {
					if (strarray[i] == ':') {
						ss.setSpan(new URLSpan(sb.toString()), startIndex, i,
								Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
						sb = null;
						start = false;
					} else {
						sb.append(strarray[i]);
					}
				}
			}

		}

		start = false;
		startIndex = 0;
		for (int i = 0; i < l; i++) {
			if (strarray[i] == '#') {
				if (!start) {
					start = true;
					sb = new StringBuffer("weibohuati://view/");
					startIndex = i;
				} else {
					sb.append('#');
					ss.setSpan(new URLSpan(sb.toString()), startIndex, i + 1,
							Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
					sb = null;
					start = false;
				}
			} else {
				if (start) {
					sb.append(strarray[i]);
				}
			}
		}

		textView.setText(ss);
		textView.setMovementMethod(LinkMovementMethod.getInstance());
		strarray = null;
	}
    
    /**
     * 获取现在与某一具体时间的相差时间 
     * @param date 某一具体
     * @return 相差时间 
     */
    public static final String getCreateAt(Date date){
		Calendar c = Calendar.getInstance();
		if(date == null){
			return "不久前";
		}
		if(c.get(Calendar.YEAR)-(date.getYear()+1900)>0){
			int i = c.get(Calendar.YEAR)-date.getYear();
			return i+"年前";
		}else if(c.get(Calendar.MONTH)-date.getMonth()>0){
			int i = c.get(Calendar.MONTH)-date.getMonth();
			return i+"月前";
		}else if(c.get(Calendar.DAY_OF_MONTH)-date.getDate()>0){
			int i = c.get(Calendar.DAY_OF_MONTH)-date.getDate();
			return i+"天前"; 
		}else if(c.get(Calendar.HOUR_OF_DAY)-date.getHours()>0){
			int i = c.get(Calendar.HOUR_OF_DAY)-date.getHours();
			return i+"小时前"; 
		}else if(c.get(Calendar.MINUTE)-date.getMinutes()>0){
			int i = c.get(Calendar.MINUTE)-date.getMinutes();
			return i+"分钟前";
		}else {
			return "刚刚";
		}
    }
	/**
	 * 去掉Activity的状态栏
	 * @param activity
	 */
	public static final void closeWindowTitleAndWindowStatusBar(Activity activity){
		closeWindowStatusBar(activity);
		closeWindowTitle(activity);
	}

    /**
     * 从指定字符源获取微博信息的来源
     * @param source 字符源 
     * @return 微博信息的来源
     */
	public static final String getComeFromSource(String source){
		 
		//System.out.println("source:" + source);
		  if(source == null){
			  return "未知"; 
		  }
		  if(source.length() <10){
			  return source;
		  }
		  String str = source.substring(source.indexOf(">")+1);
	      return str.substring(0, str.length()-4);
	}
    
	/**
	 * 获取当前所在地的经度和纬度
	 * @param context  上下文
	 * @return 当前所在地的经度和纬度
	 */
	public static final double[] getGPSPoint(Context context){
		//得到GPS设备的访问
		final LocationManager locationManager = 
			(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		final Criteria criteria = new Criteria();
 
		criteria.setAccuracy(Criteria.ACCURACY_FINE);
		criteria.setAltitudeRequired(false);
		criteria.setBearingRequired(false);
		criteria.setCostAllowed(false);
		criteria.setPowerRequirement(Criteria.POWER_LOW);
 
		final String provider = locationManager.getBestProvider(criteria, true);
 
		final Location location = locationManager.getLastKnownLocation(provider);
       //获取GPS传感器的坐标信息
		final Double latitude = location.getLatitude() * 1E6;
		final Double longitude = location.getLongitude() * 1E6;
		double point[]={latitude,
        		longitude};
        return point;
	}
	
	
	/**
	 * 从网络上下载图片
	 * @param url 图片地址对象
	 * @return 网络上下载的图片
	 */
	public static final BitmapDrawable loadImageFromNet(final URL url){
		   //从网络获取用户的头像
	   BitmapDrawable bd = null;
		try {
			bd = WeiboUtil.getImageFromURL(url);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bd;
	}
	
	/**
	 * 从网络上下载图片
	 * @param urlStr 图片地址
	 * @return
	 * @throws IOException 
	 */
	public final static Drawable loadIBitmapDrawable(final String urlStr) throws IOException{
		Drawable drawable = null;
			if(urlStr == null || urlStr.length() == 0){
				//System.out.println("----------图片地址不对吧 都是空的----------");
			}
			final URL url = new URL(urlStr);
			final InputStream inputStream = (InputStream) url.getContent();
			drawable = Drawable.createFromStream(inputStream, "src");
		return drawable;
	}
	
	
//	// 进度条
//	public static Toast myToastShow(ListAllFriendsActivity context, String msg) {
//
//		Toast toast = Toast.makeText(context, msg,Toast.LENGTH_LONG);
//		// 设置显示位置
//		toast.setText(msg);
//		toast.setGravity(Gravity.CENTER, 0, 0);
//
//		LinearLayout toastView = (LinearLayout) toast.getView();
//		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);
//		toastView.setOrientation(LinearLayout.HORIZONTAL);
//		ProgressBar progressBar = new ProgressBar(context);
//		progressBar.setLayoutParams(params);
//		toastView.addView(progressBar, 0);
//		toastView.setLayoutParams(new LinearLayout.LayoutParams(20, 25));
//		toast.show();
//		
//		return toast;
//	}
	// 树朾添加--------------------------------------
	
	public final static Toast myToastShowProceessBar(final Context context, final String msg){
//		return Toast.makeText(context, msg, Toast.LENGTH_SHORT);
//		return Toast.makeText(context, msg,10000);
		 final Toast toast =  Toast.makeText(context , msg, 60000);
	      //设置显示位置
	      toast.setGravity(Gravity.CENTER, 0, 0);
	      final LinearLayout toastView = (LinearLayout) toast.getView();
	      final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);
	      toastView.setOrientation(LinearLayout.HORIZONTAL);
	      ProgressBar progressBar = new ProgressBar(context);
	      progressBar.setLayoutParams(params);
	      toastView.addView(progressBar, 0);
	      toastView.setLayoutParams(new LinearLayout.LayoutParams(20, 25));
	      return toast;
	}
	
	public final static void myToastShow(final Context context, final String msg){
		Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
	}
	
	public final static void myToastShow(final Context context, final String msg, int time){
		Toast.makeText(context, msg, time).show();
	}
	
	
	///////////////////////////////////////////////////////////////
	

	public static void myToastShow(Context context) {
		Toast toast = Toast.makeText(context, "发送中,请稍等....", 20000);
		// 设置显示位置
		toast.setGravity(Gravity.CENTER, 0, 0);

		LinearLayout toastView = (LinearLayout) toast.getView();
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);
		toastView.setOrientation(LinearLayout.HORIZONTAL);
		ProgressBar progressBar = new ProgressBar(context);
		progressBar.setLayoutParams(params);
		toastView.addView(progressBar, 0);
		toastView.setLayoutParams(new LinearLayout.LayoutParams(20, 25));
		toast.show();
	}


	


	
	/**
	 * 保存用户登陆信息
	 * @param context 上下文句柄
	 * @param username 用户名(emial)
	 * @param password 登陆密码
	 * @param name 用户昵称
	 */
	public static final void saveUserLoginParam(Context context, String username, String password, String name){
	   SharedPreferences sharedPreferences = context.getSharedPreferences("loginparam", Activity.MODE_PRIVATE);
	   sharedPreferences.edit().putString("username", username)
	                           .putString("password", password)
	                           .putString("name", name)
	                           .commit();
	}
	
	/**
	 * 获取登录用户信息
	 * @param context 上下文句柄
	 * @return
	 */
	public static final String[] getUserLoginParam(Context context){
		SharedPreferences sharedPreferences = context.getSharedPreferences("loginparam", Activity.MODE_PRIVATE);
		String[] params = new String[3];
		try {
			params[0] = sharedPreferences.getString("username", null);
			params[1] = sharedPreferences.getString("password", null);
			params[2] = sharedPreferences.getString("name", null);
		} catch (Exception e) {
			 Log.e("ERROR", "数据库中找不到可用的记录");
			 e.printStackTrace();
		}
	
		return params;
	}
	
	
	
	
	/**
	 * 计算微博信息的权重(rtNum: commNum = 2:1)
	 * @param rtNum 转发的条数
	 * @param commNum 评论的条数
	 * @return 某条博信息的权重
	 */
	public static final long calStatusWeight(long rtNum, long commNum){
		return (long)(rtNum * 0.67 + commNum * 0.33);
	}
	
	/**
	 * 降序排列
	 * @param data
	 */
	public static final void sort(long data[]){
		// 比较的轮数 
	       for (int i = 1; i < data.length; i++) { 
	           // 将相邻两个数进行比较，较大的数往后冒泡 
	           for (int j = 0; j < data.length - i; j++) { 
	               if (data[j] < data[j + 1]) { 
	                   // 交换相邻两个数 
	                   swap(data, j, j + 1); 
	               } 
	           } 
	       }
	} 
   private static void swap(long[] data, int x, int y) { 
	   long temp = data[x]; 
       data[x] = data[y]; 
       data[y] = temp; 
   }  
    
   /**
    * 处理评论列表的任务
    * @param allc
    */
   public static final void processComment(ArrayList<Comment> allc){
	   User user = null;
	   for(Comment comment : allc){
		  user = comment.getUser();
		  if(MainService.allIcon.get(user.getId()) == null){
		     HashMap param = new HashMap();
			 param.put("uid", user.getId());
			 param.put("url", user.getProfileImageURL());
			 Log.d("user", user.getId() + "-----"+ user.getProfileImageURL());
			 Task ts = new Task(Task.TASK_GET_COMM_USERT_ICON, param);
			 MainService.addNewTask(ts);
		  }
	   }
   }
   /**
    * 处理私信列表的任务
    * @param allc
    */
   public static final void processSendMessageDirect(ArrayList<DirectMessage> alld){
	   User user = null;
	   for(DirectMessage directMessage : alld){
		   user = directMessage.getSender();
		   if(MainService.allIcon.get(user.getId()) == null){
			   HashMap param = new HashMap();
			   param.put("uid", user.getId());
			   param.put("url", user.getProfileImageURL());
			   Log.d("user", user.getId() + "-----"+ user.getProfileImageURL());
			   Task ts = new Task(Task.TASK_GET_DIRECT_MSG_USERT_ICON, param);
			   MainService.addNewTask(ts);
		   }
	   }
   }
 
   /**
    * 处理微博信息列表的任务等
    * @param alls
    * @param userIconTaskId 加载用户图标的任务ID
    * @param weibomageTaskId  加载微博图片的任务ID
    */
	public static final void processStatuses(ArrayList<Status> alls, int userIconTaskId, int weibomageTaskId){
		User user = null;
		String bmiddlePic = null;
		String retweetedbmiddlePic = null;
		Status retweetedStatus = null;
		
		for (Status status : alls) { // 该用户的头像没有获取过
		   user = status.getUser();
			if (MainService.allIcon.get(user.getId()) == null) {
				HashMap param = new HashMap();
				param.put("uid", user.getId());
				param.put("url", user.getProfileImageURL());
				Log.d("user", user.getId() + "-----"+ user.getProfileImageURL());
				Task ts = new Task(userIconTaskId, param);
				MainService.addNewTask(ts);
			}
			 bmiddlePic = status.getBmiddle_pic();
			if(WeiboUtil.strIsNotEmpty(bmiddlePic)){
				 HashMap param = new HashMap();
	    		 param.put("imageUrl",  bmiddlePic );
	    		 param.put("statusId",  status.getId());
	    		 Task loadWeiboImageTask = new Task(weibomageTaskId, param);
	    		 MainService.newTask(loadWeiboImageTask);
			}
			retweetedStatus = status.getRetweetedStatus();
			if(retweetedStatus != null){
				retweetedbmiddlePic = retweetedStatus.getBmiddle_pic();
				if(WeiboUtil.strIsNotEmpty(retweetedbmiddlePic)){
					HashMap param = new HashMap();
		    		param.put("imageUrl", retweetedbmiddlePic );
		    		param.put("statusId", retweetedStatus.getId());
		    		Task loadWeiboImageTask = new Task(weibomageTaskId, param);
		    		MainService.newTask(loadWeiboImageTask);
				}
			}
		}
	}
    
	public static final void processFans(ArrayList<User> fans){
		 User user = null;
	     HashMap param = null;
	     Task tssss  = null;
	     for (Iterator iterator = fans.iterator(); iterator.hasNext();) {
			user = (User) iterator.next();
			param = new HashMap();
			param.put("uid", user.getId());
			param.put("url", user.getProfileImageURL());

		    tssss = new Task(Task.TASK_GET_USER_IMAGE_ICON_FANS, param);
			MainService.addNewTask(tssss); 
	    }
	}
	/**
	 * 处理有一个用户的地址
	 * @param uid 用户ID
	 * @param url 用户头像地址
	 * @param weiboManager 
	 */
	public static final void processUserIcon(Integer uid, URL url, WeiboManager weiboManager ){
	    //首先从缓存中获取数据
	    Bitmap bitmap = weiboManager.getMyBitmap(String.valueOf(uid));
        if(bitmap != null){ 
        	MainService.allIcon.put(uid, bitmap);
        }else{
		    BitmapDrawable bitmapDrawable = null;
			try {
				//从网络上加载数据
				bitmapDrawable = WeiboUtil.getImageFromURL(url);
				//添加到集合
			    MainService.allIcon.put(uid, bitmapDrawable.getBitmap());
			   
			    final HashMap taskparamMap2 = new HashMap();
			    taskparamMap2.put("imageId", String.valueOf(uid));
			    taskparamMap2.put("imageResource", bitmapDrawable.getBitmap());
			    Task saveImageTask2 = new Task(Task.TASK_SAVE_IMAGE_TO_SD_CARD, taskparamMap2);
			    MainService.addNewTask(saveImageTask2);
			} catch (IOException e) {
				e.printStackTrace();
			}
		   
        }
	}
	public static final void processSattusImage(long statusId, String imageUrl, WeiboManager weiboManager ){
 
		 Bitmap statusBitmap = weiboManager.getMyBitmap(String.valueOf(statusId));
	     if(statusBitmap != null){
	     	MainService.putAllImage(statusId, statusBitmap);
	     }else{
			    BitmapDrawable drawable;
				try {
					drawable = (BitmapDrawable) WeiboUtil.loadIBitmapDrawable(imageUrl);
					 //-----找到了一个BUG了
				    MainService.putAllImage(statusId, drawable.getBitmap());
				  
				    final HashMap taskparamMap2 = new HashMap();
				    taskparamMap2.put("imageId", String.valueOf(statusId));
				    taskparamMap2.put("imageResource", drawable.getBitmap());
				    Task saveImageTask2 = new Task(Task.TASK_SAVE_IMAGE_TO_SD_CARD, taskparamMap2);
				    MainService.addNewTask(saveImageTask2);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			   
	     }
	}
	
//------------------------------------------------------------------------	
	public static final boolean checkNet(Context context) {// 获取手机所有连接管理对象（包括对wi-fi,net等连接的管理）
		try {
			ConnectivityManager connectivity = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			if (connectivity != null) {
				// 获取网络连接管理的对象
				NetworkInfo info = connectivity.getActiveNetworkInfo();
				if (info != null && info.isConnected()) {
					// 判断当前网络是否已经连接
					if (info.getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
		} catch (Exception e) {
		}
		return false;
	}

	/**
	 * 从一个URL获取图片
	 * @param url
	 * @return
	 * @throws IOException
	 */
	public static final BitmapDrawable getImageFromURL(URL url) throws IOException {
		BitmapDrawable bd = null;
		// 创建连接
		HttpURLConnection hc = (HttpURLConnection) url.openConnection();
		// 获取数据
		bd = new BitmapDrawable(hc.getInputStream());
		// 关闭连接
		hc.disconnect();
		 
		return bd;
	}
    
	/**
	 * 获取微博的推荐值
	 * @param rtNum  转发数
	 * @param commNum 评论数
	 * @return 微博的推荐值
	 */
	public static final float getStatusRecommendWeight(long rtNum, long commNum){
//		double weiboWeight = rtNum * 0.01 + commNum * 0.003;
		DecimalFormat decimalFormat = new DecimalFormat("#0.0");
//		return String.valueOf(decimalFormat.format( rtNum * 0.01 + commNum * 0.003));
		return  Float.parseFloat(decimalFormat.format( rtNum * 0.015 + commNum * 0.005));
	} 
	
	/**
	 * 获取用户的推荐值
	 * @param fansNum 粉丝数
	 * @param attentionNum 关注数
	 * @param statusNum 发表的微博数
	 * @return  取用户的推荐值
	 */
	public static final float getUserRecommendWeight(long fansNum, long attentionNum, long statusNum){
//		double userWeight = fansNum * 0.00006 + attentionNum * 0.000003 + statusNum*0.00005;
		DecimalFormat decimalFormat = new DecimalFormat("#0.0");
		return  Float.parseFloat(decimalFormat.format(fansNum * 0.00006 + attentionNum * 0.000003 + statusNum*0.00005));
	} 
	
	/**
	 * 根据权值返回信息推荐等级
	 * @param weight 权值 
	 * @return 信息推荐等级
	 */
	public static final int getLevelByWeight(float weight){
		if(weight < 1.9){
			return 1;
		}else if(weight < 3.9){
			return 2;
		}else if(weight < 5.9){
			return 3;
		}else if(weight < 7.9){
			return 4;
		}else if(weight < 9.9){
			return 5;
		}else{
			return 6;
		}
	}
	
	 /**
	  * 渲染推荐等级到Activity(UI)
	  * @param weight  权值
	  * @param weightLevel 权值等级
	  * @param btnRecommendWeightInfo  要渲染到得Button
	  */
	public static final void setRecommendStatusWeightToWiew(float weight, int weightLevel, Button btnRecommendWeightInfo){
		
		btnRecommendWeightInfo.setText(new StringBuffer().append("  ").append(weight).toString());
		
		switch (weightLevel) {
		case 1:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_1);
			break;
		case 2:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_2);
			break;
		case 3:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_3);
			break;
		case 4:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_4);
			break;
		case 5:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_5);
			break;
		case 6:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_5);
			break;

		default:
			break;
		}
	}
	
public static final void setRecommendUserWeightToWiew(float weight, int weightLevel, Button btnRecommendWeightInfo){
		
		btnRecommendWeightInfo.setText(new StringBuffer().append("  ").append(weight).toString());
		
		switch (weightLevel) {
		case 1:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_1);
			break;
		case 2:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_2);
			break;
		case 3:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_3);
			break;
		case 4:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_4);
			break;
		case 5:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_5);
			break;
		case 6:
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_5);
			break;

		default:
			break;
		}
	}
	
	public static final void setRecommendStatusWeightToWiew(float weight, Button btnRecommendWeightInfo){
		//推荐权值等级
		int weightLevel = WeiboUtil.getLevelByWeight(weight);
		
		
		switch (weightLevel) { //根据推荐权值等级渲染控件背景
		case 1: 
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_1);
			break;
		case 2:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_2);
			break;
		case 3:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_3);
			break;
		case 4:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_4);
			break;
		case 5:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_5);
			break;
		case 6:
			//将推荐权值渲染到UI
//			if(weight < 20){ //一个" + "
				btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append("10+"));
				btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_5);
				break;
//			}else if(weight < 40){
//				btnRecommendWeightInfo.setText(new StringBuffer().append("  ").append("10++"));
//				btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_5);
//				break;
//			}else{
//				btnRecommendWeightInfo.setText(new StringBuffer().append("  ").append("10++"));
//				btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_status_level_5);
//				break;
//			}
//			
			
			
		default:
			break;
		}
	}
	public static final void setRecommendUserWeightToWiew(float weight, Button btnRecommendWeightInfo){
		//推荐权值等级
		int weightLevel = WeiboUtil.getLevelByWeight(weight);
		
		
		switch (weightLevel) { //根据推荐权值等级渲染控件背景
		case 1: 
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_1);
			break;
		case 2:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_2);
			break;
		case 3:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_3);
			break;
		case 4:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_4);
			break;
		case 5:
			//将推荐权值渲染到UI
			btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append(weight).toString());
			btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_5);
			break;
		case 6:
			//将推荐权值渲染到UI
//			if(weight < 20){ //一个" + "
				btnRecommendWeightInfo.setText(new StringBuffer().append("   ").append("10+"));
				btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_5);
				break;
//			}else if(weight < 40){
//				btnRecommendWeightInfo.setText(new StringBuffer().append("  ").append("10++"));
//				btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_5);
//				break;
//			}else{
//				btnRecommendWeightInfo.setText(new StringBuffer().append("  ").append("10++"));
//				btnRecommendWeightInfo.setBackgroundResource(R.drawable.recomm_user_level_5);
//				break;
//			}
			
			
			
		default:
			break;
		}
	}
}
